package com.wikilife.index;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;

import com.bigkoo.convenientbanner.holder.Holder;
import com.oklib.widget.recyclerview.BaseQuickAdapter;
import com.oklib.widget.recyclerview.BaseViewHolder;
import com.oklib.widget.recyclerview.CoreRecyclerView;
import com.oklib.widget.recyclerview.listener.OnItemClickListener;
import com.wikilife.R;
import com.wikilife.index.model.IndexEntrance;

import java.util.List;

public class NetworkImageHolderView implements Holder<List<IndexEntrance>> {
    CoreRecyclerView coreRecyclerView;

    @Override
    public View createView(Context context) {
        View mainView = LayoutInflater.from(context).inflate(R.layout.fragment_index_top, null);
        coreRecyclerView = (CoreRecyclerView) mainView.findViewById(R.id.recycler);
        coreRecyclerView.init(new GridLayoutManager(context, 5), new BaseQuickAdapter<IndexEntrance, BaseViewHolder>(R.layout.layout_img_with_txt) {
            @Override
            protected void convert(BaseViewHolder helper, IndexEntrance item) {
                helper.setText(R.id.txt, item.text);
                helper.setImageResource(R.id.img, item.drawId);
            }
        });
        return mainView;
    }

    @Override
    public void UpdateUI(Context context, int position, List<IndexEntrance> data) {
        coreRecyclerView.getAdapter().addData(data);
        coreRecyclerView.addOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {

            }
        });
    }

}
